package com.hongying.controller;

import com.hongying.bean.Simple;
import com.hongying.constant.RabbitMqConstant;
import com.hongying.producer.*;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.UUID;



@RestController
@RequestMapping("test")
public class TestRabbitMqController {


    @Autowired
    private SimpleProducer simpleProducer;

    @Autowired
    private DirectSender directSender;

    @Autowired
    private HelloSender helloSender;

    @Autowired
    private FanoutSender fanoutSender;

    @Autowired

    private TopicSender topicSender;

    @Autowired
    private DelaySender delaySender;



    @GetMapping("index")
    public String index(){
        for (int i=1;i<20;i++){
            String uuid = UUID.randomUUID().toString();
            simpleProducer.sendOrderMessage(Simple.builder().createTime(new Date()).name("xiaoming"+i).age(20).id(uuid).phone("138XXXXXXXX").build());

        }


        return "test success";
    }

    @GetMapping("hello")
    public String hello(){
        helloSender.send();

        return  "test hello";
    }


    @GetMapping("direct")
    public String direct(){
        directSender.send();
        return  "test direct";
    }

    @GetMapping("fanout")
    public String fanout(){
        String message = "Message from Fanout";

        fanoutSender.send(RabbitMqConstant.FANOUT_EXCHANGE,RabbitMqConstant.GOOGLE_QUEUE, message);


        return "fanout success";

    }


    @GetMapping("topic")
    public String topicMessage(){
        String message = "Message from topic.message.";
        topicSender.send(RabbitMqConstant.TOPIC_EXCHANGE,RabbitMqConstant.MESSAGE,message);



        return  "topic success";
    }

    @GetMapping("delay")
    public String topicDelayMessage(){


        return "topic success";
    }

    //开始发消息 基于插件的  消息及延迟的时间
    @GetMapping("/sendDelayMsg/{delayTime}")
    public String sendDelayMsg(@PathVariable Integer delayTime){

        String message = "延时时间到了哈！";

        delaySender.sendDelayMsg(message,delayTime);


        return "delay success";
    }






}
